<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8" />
    <title>注册-极客</title>
    <#--/公共引入包-->
    <#include "include.ftl">
    <#---->
    <style>
        .tips{
            color:red;
            margin-bottom:10px;
            display: none;
        }
    </style>
</head>
<body class="background_grey">

    <#--/header-->
    <#include "header.ftl">
    <#---->

    <div class="creation_detail">
        <div class="creation_detail_in">
            <div class="creation_detail_title">
                <h3>我是极客</h3>
                <p>注册为极客后你将可以参与项目投标</p>
                <ul id="choice_identity">
                    <li id="1" class="active"><a href="javascript:;">个人</a></li>
                    <li id="2"><a href="javascript:;">企业</a></li>
                </ul>
            </div>
            <div class="creation_detail_ipt phone">
                <span class="creation_detail_ipt_icon"></span>
                <input id="mobile" type="text" placeholder="请输入手机号码" id="creat_phone" maxlength="11" />
            </div>
            <div class="creation_detail_ipt creation_detail_ipt_code code">
                <span class="creation_detail_ipt_icon"></span>
                <input id="regCode" type="text" placeholder="请输入收到的验证码"  id="creat_code"/>
                <span id="code_but" class="creation_detail_ipt_send">发送验证码</span>
            </div>
            <div class="creation_detail_ipt nickname">
                <span class="creation_detail_ipt_icon"></span>
                <input id="userName" type="text" placeholder="请输入4-12位的用户昵称"  id="creat_nickname"/>
            </div>
            <div class="creation_detail_ipt password1">
                <span class="creation_detail_ipt_icon"></span>
                <input id="password1" type="password" placeholder="请输入5位以上的用户密码"  id="creat_password1"/>
            </div>
            <div class="creation_detail_ipt password2">
                <span class="creation_detail_ipt_icon"></span>
                <input id="password2" type="password" placeholder="请重复输入用户密码"  id="creat_password2"/>
            </div>
            <div class="tips"></div>
            <div class="creation_detail_btn" id="creation_btn">立即注册</div>
            <div class="creation_detail_link">
                <div class="creation_detail_link_agree">
                    <span></span>同意用户协议，<i>查看协议</i>
                </div>
                <div class="creation_detail_link_enter"><a href="/user/tologin">已有账户，立即登录</a></div>
            </div>
        </div>
    </div>
    <div class="index_footer">
        <div class="index_footer_link">
            <a href="">新闻公告</a>|
            <a href="">关于我们</a>|
            <a href="">联系我们</a>|
            <a href="">用户协议</a>
        </div>
        <p class="index_footer_copy">Copyright©2016 yk-zb.com 粤科众包 版权所有 粤ICP备16027165号-1</p>
    </div>
</body>
<script type="text/javascript" src="/js/validate_input_data_1.0.js"></script>
<script type="text/javascript" src="/js/md5.js"></script>
</html>
<script type="text/javascript">
    var role = 1;
    var ifSubmiting = false;
    $(function() {

        (function fnHeight(){
            var iHeight = $(window).height();
            var navHeight = $('.header').height();
            var footHeight = $('.index_footer').height();
            var registerHeight = $('.creation_detail').height()+170;
            if(navHeight + footHeight + registerHeight < iHeight){
                $('.index_footer').css({"position":"absolute","bottom":"0"})
            }else{
                $('.index_footer').css({"position":"static"})
            }
            
        })();
        $('.creation_detail_link_agree').click(function(event) {
            if($(this).hasClass('active')){
                $(this).removeClass('active');
            }else{
                $(this).addClass('active');
            }
        });

        $('.creation_detail_ipt_send').click(function(){
            var moblile = $('#mobile').val();
            if(moblile && wait==60){
                $.ajax({
                    type:"POST",
                    url:"/user/getregistercode",
                    data:{mobile:moblile},
                    datatype:"json",
                    success:function(data){
                        countTime();
                        if(!data || !data.success){
                            $('.tips').text("获取验证码失败！");
                            $('.tips').show();
                        }else{
                            $('.tips').text("");
                            $('.tips').hide();
                        }
                    }
                })
            }else{
                $('.tips').text("手机号为空，不能发送验证码！");
                $('.tips').show();
            }
        });

        /*提交*/
        $('#creation_btn').click(function(event) {
            var registerPhone = $('#mobile').val();
            var registerPassword = $('#password1').val();
            var registerPasswordAgain = $('#password2').val();
            var registerCode = $('#regCode').val();
            var userName = $('#userName').val();
            if(!registerPhone){
                $('.tips').text("请填写手机号码！");
                $('.tips').show();
                return false;
            }
            if(!checkPhone(registerPhone)){
                $('.tips').text("请填写正确的手机号码！");
                $('.tips').show();
                return false;
            }
            if(!registerCode){
                $('.tips').text("请填写验证码！");
                $('.tips').show();
                return false;
            }
            if(!userName){
                $('.tips').text("请填写用户名！");
                $('.tips').show();
                return false;
            }
            if(!registerPassword){
                $('.tips').text("请填写密码！");
                $('.tips').show();
                return false;
            }
            if(!registerPasswordAgain){
                $('.tips').text("请再次填写密码！");
                $('.tips').show();
                return false;
            }
            if(registerPassword != registerPasswordAgain){
                $('.tips').text("两次输入的密码不一样！");
                $('.tips').show();
                return false;
            }
            if(!$('.creation_detail_link_agree').hasClass('active')){
                $('.tips').text("请你先同意服务条款！");
                $('.tips').show();
                return false;
            }
            if(!ifSubmiting){
                $('#register_btn').text("提交中...");
                $('.tips').text("");
                register(registerPhone,registerPassword,registerCode,userName);
            }

        });

        $('#choice_identity li').click(function(event) {
            $('#choice_identity li').removeClass('active');
            $(this).addClass('active');
            role = $(this).attr("id");
        });

    });
    function register(registerPhone,registerPassword,registerCode,userName){
        ifSubmiting = true;
        $.ajax({
            type: "POST",
            url: '/talent/registerTalent',   //提交地址
            data : {
                mobile:registerPhone,
                pwd:$.md5(registerPassword),
                code:registerCode,
                nickname:userName,
                role:role
            },
            dataType: "json",
            success: function(data){
                $('#register_btn').text("马上注册");
                ifSubmiting = false;
                if(data.success){
                    //信息框-例3
                    layer.msg('注册成功！正在跳转至项目大厅...');
                    setTimeout(function() {
                        window.location.href = "/project/searchproject"; //跳转到项目大厅
                    }, 3000)
                }else{
                    $('#register_btn').text("马上注册");
                    $('.tips').text("注册失败！");
                    $('.tips').show();
                }
            },
            error: function(data){
                ifSubmiting = false;
                $('#register_btn').text("马上注册");
                $('.tips').text("注册失败！");
                $('.tips').show();
            }
        });
    }

    var wait=60;
    function countTime(){
        if (wait == 0) {
            $("#code_but").text("获取验证码");
            wait = 60;
        } else {
            setTimeout(function() {
                wait--;
                $("#code_but").text("重新发送(" + wait + ")");
                countTime();
            }, 1000)
        }
    }
</script>